package com.zyh.server.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * @Author: zyh
 * @Date: 2024-11-20-11:02
 * @Description redis客服端，支持分布式锁
 */
@Configuration
public class RedissonConfig {
	@Value("${spring.redis.redisson.config}")
	private String config;

	//获取redis分布式锁客户端
	@Bean
	public RedissonClient redissonClient() {
		try {
			//1.读取RedissonProperties对象中的内容
			Config myConfig = Config.fromYAML(config);
			RedissonClient client = Redisson.create(myConfig);
			System.out.println("RedissonClient客户端已启动！");
			//2.创建客户端
			return client;
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
}
